$(function () {
    let locationName = localStorage.getItem('username');
	if (locationName == null) {
		$('.login').html(' <a class="nav-link" href="./login.html">登录</a>')
		$('.register').html('<a class="nav-link" href="./register.html">注册</a>')
	} else {
		$('.login').html(` <a class="nav-link" href="#">${locationName}</a>`)
		$('.register').html(`<a class="nav-link" href="#" id="del">注销</a>`)


	}
    $('#btn').click(function () {
        let id =sessionStorage.getItem('id')
        console.log(id);
        $('#cradid').html(`
        <option value="${id}">中国银行</option>
        <option value="${id}">汇丰银行</option>
        `)
        
        let userid = sessionStorage.getItem('userid');
        let cardid = $('#cradid option:selected').val();
        let money = $('#money').val();
        //console.log(userid,cradid,money);
        $.ajax({
            url: 'http://139.9.177.51:3333/p2p/charge',
            type: 'post',
            data: { userid, cardid, money },
            dataType: 'json',
            success: function (res) {
                if (res.code == 200) {
                   alert('充值成功');
                    location.href='/index.html#personage/info'
                } else {
                   alert('充值失败');
                }
            }
        })
       
    }) 
})